<template>
  <layout>
    <!-- Page Header -->
    <header class="masthead" :style="{
      backgroundImage:`url(http://localhost:1337${$page.general.edges[0].node.cover.url})`
    }">
      <div class="overlay"></div>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            <div class="site-heading">
              <h1>{{$page.general.edges[0].node.title}}</h1>
              <span class="subheading">{{$page.general.edges[0].node.subtile}}</span>
            </div>
          </div>
        </div>
      </div>
    </header>

    <!-- Main Content -->
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          <div
            class="post-preview"
            v-for="post in $page.posts.edges"
            :key="post.node.id"
          >
            <g-link :to="'/post/'+post.node.id">
              <h2 class="post-title">
                {{ post.node.title }}
              </h2>
              <!-- <h3 class="post-subtitle">
                {{post.node.content}}
              </h3> -->
            </g-link>
            <p class="post-meta">
              Posted by
              <a href="#">Start Bootstrap</a>
              on {{ post.node.created_at }}
            </p>
            <p>
              <g-link v-for="tag in post.node.tags" :key="tag.id" :to="'/tag/'+tag.id"
                >{{ tag.title }}&nbsp;&nbsp;</g-link
              >
            </p>
            <hr />
          </div>
          <Pager :info="$page.posts.pageInfo" />

          <!-- <hr /> -->
          <!-- Pager -->
          <div class="clearfix">
            <a class="btn btn-primary float-right" href="#"
              >Older Posts &rarr;</a
            >
          </div>
        </div>
      </div>
    </div>
    <!-- Footer -->
  </layout>
</template>
<page-query>
query($page: Int) {
  posts: allStrapiPost(perPage: 2, page: $page) @paginate{
     pageInfo {
      totalPages
      currentPage
    }
    edges {
      node {
        id
        title
        content
        created_at
        tags {
        title
        id
        }
      }
    }
  }
  general: allStrapiGeneral{
    edges{
      node{
        title
        id
        subtile
        cover{
          url
        }
      }
    }
  }
}

</page-query>
<script>
import { Pager } from "gridsome";

export default {
  components: {
    Pager,
  },
  metaInfo: {
    title: "Hello, world!",
  },
};
</script>

<style>
</style>
